<?php
/**
 * Created by PhpStorm.
 * User: Shen
 * Date: 2016/6/23
 * Time: 21:45
 */
include_once 'database.php';

function likecate($path=''){
    $sql = "SELECT id,catename,path,concat(path,',',id) AS fullpath FROM likecate ORDER BY fullpath ASC ";
    $res = mysql_query($sql);
    $result = array();
    while ($row = mysql_fetch_assoc($res)){
        $deep = count(explode(',',trim($row['fullpath'],',')));
        $row['catename'] = str_repeat('&nbsp;',$deep * 4) . '|--' . $row['catename'];
        $result[] = $row;
    }
    return $result;
}




function display(){
    $res = likecate();
    $str = '';
    $str .= "<select name='cate'>";
    foreach ($res as $key => $val) {
        $str .= "<option >{$val['catename']}</option>";
    }
    $str .= "</select>";

    return $str;
}

echo display();